

class {$mtable}Action extends Action{

	// 查询数据
	public function index(){
        ${$mtable} = M("{$mtable}");
        import("ORG.Util.Page"); 
        $where = '';
        $count = ${$mtable}->where($where)->count(); 
        $p = new Page($count,10);
        $list = ${$mtable}->where($where)->limit($p->firstRow.','.$p->listRows)->select();
		$page = $p->show ();
        $this->assign('list',$list);
        $this->assign('page',$page);
		$this->display();
	}
	// 写入数据
	public function insert() {
		${$mtable} = D("{$mtable}");
		if($vo = ${$mtable}->create()) {
			$list=${$mtable}->add();
			if($list!==false){
				$this->success('数据保存成功！');
			}else{
				$this->error('数据写入错误！');
			}
		}else{
			$this->error(${$mtable}->getError());
		}
	}
	// 更新数据
	public function update() {
		${$mtable} = D("{$mtable}");
		if($vo = ${$mtable}->create()) {
			$list=${$mtable}->save();
			if($list!==false){
				$this->success('数据更新成功！');
			}else{
				$this->error("没有更新任何数据!");
			}
		}else{
			$this->error(${$mtable}->getError());
		}
	}
	// 删除数据
	public function delete() {
    	$id = isset($_GET['id']) && intval($_GET['id']) && is_numeric($_GET['id']) ? $_GET['id'] : 0;
		if($id > 0) {
			${$mtable} = M("{$mtable}");
			$result	= ${$mtable}->where("id=".$id)->delete();
			if(false !== $result) {
				$this->success('删除成功！');
			}else{
				$this->error('删除出错！');
			}
		}else{
			$this->error('删除项不存在！');
		}
	}
	// 编辑数据
	public function edit() {
        $id = isset($_GET['id']) && intval($_GET['id']) && is_numeric($_GET['id']) ? $_GET['id'] : 0;
		if($id > 0) {
			${$mtable} = M("{$mtable}");
			$info = ${$mtable}->where("id=".$id)->find();
			if($info) {
				$this->assign('info',$info);
				$this->display();
			}else{
				$this->error('编辑项不存在！');
			}
		}else{
			$this->error('编辑项不存在！');
		}
	}

}


